package com.mc.sort;

import java.util.Arrays;

/**
 * @Description: 快速排序
 * @Author: MoChen
 */
public class QuickSort {
    public static void main(String[] args) {
        int[] arrs = {1, 2, 5, 3, 6, 7, 4};
        QuickSort qs = new QuickSort();
        System.out.println(Arrays.toString(qs.quickSort(arrs, 0, arrs.length - 1)));
    }

    /**
     * 快速排序
     */
    public int[] quickSort(int[] arrs, int low, int high){
        int i = low, j = high;
        int temp = 0;
        if(i < j){
            temp = arrs[i];
            while(i != j){
                while(j > i && arrs[j] > temp){
                    --j;
                }
                arrs[i] = arrs[j];
                while(i < j && arrs[i] < temp){
                    ++i;
                }
                arrs[j] = arrs[i];
            }
            arrs[i] = temp;
            quickSort(arrs, low, i - 1);
            quickSort(arrs, i + 1, high);
        }
        return arrs;
    }
}
